﻿{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <!--列表部分-->
            <div id="user" class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="row common-search" style="margin-top: 10px;margin-bottom: 20px" hidden>
                        <div class="col-sm-12">
                            <form class="form-inline table-form">
                                <!--搜索项-->
                                <div class="form-group">
                                    <input type="text" name="name" placeholder="请输入登录名" class="form-control">
                                </div>
                                <!--此处可自定义查询条件-->
                                <!--搜索项-->
                                {$html->search_btn()}
                            </form>
                        </div>
                    </div>
                    <div  class="toolbar">
                        {$html->toolbar()}
                        <!--此处可自定义工具栏-->
                        <!--<button class="btn btn-primary btn-sm" type="button"><i class="fa fa-plus"></i> 自定义</button>&nbsp;-->
                    </div>
                    <table class="table table-striped table-hover table-bordered"></table>
                    <input id="tableName" value="" type="hidden">
                </div>
            </div>
        </div>
        <!--/列表部分-->
    </div>
</div>
{include file="public/footer" /}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    //初始化表格
    var tableName="user";
    initTable({
        name:tableName,
        config:{
            index_url: '/admin/sys.user/loadData',
            add_url: '/admin/sys.user/add',
            del_url: '/admin/sys.user/del',
            table: tableName
        },
        columns:[
            {checkbox: true},
            {title: 'ID',field:'id'},
            {title: '头像', field: 'head_img',formatter:function(v){return getImgField(v)}},
            {title: '登录名', field: 'login_name'},
            {title: '用户名', field: 'user_name'},
            {title: '角色', field: 'role_name'},
            {title: '状态', field: 'status',formatter:function(v, row){
                var str="";
                if(v==0){
                    str += '<span style="cursor:pointer" class="label label-primary" onclick="admin_stop('+row.id+','+row.status+');">已启用</span>';
                }else{
                    str += '<span style="cursor:pointer" class="label label-default" onclick="admin_stop('+row.id+','+row.status+');">已禁用</span>';
                }
                return str;
            }},
            {title: '创建时间', field: 'ct'},

            {title: '操作', field: 'operate',formatter: function (value, row){
                var str="";
                var editUrl="/admin/sys.user/add?id=" +row.id ;
                var e = ' <button class="btn btn-primary btn-xs" type="button" onclick="layer_open(\''+editUrl+'\',\'编辑\')"><i class="fa fa-edit"></i> 编辑</button> ';
                str+=e;
                var delUrl="/admin/sys.user/del?id="+row.id;
                var d = '<button class="btn btn-danger btn-xs" type="button" onclick="table_del(\''+delUrl+'\',\''+tableName+'\');"><i class="fa fa-trash"></i> 删除</button>';
                str+=d;
                return str;
            }}
        ]
    });

    /*以下自定义*/
    /*管理员-停用*/
    function admin_stop(id,status){
        var str="禁用";
        if(status==1){
            str="启用";
            status=0;
        }else{
            status=1;
        }
        layer.confirm('您确定要'+str+'吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            //提交后台
            $.ajax({
                url:'status?id='+id+'&status='+status,
                type:'get',
                dataType:'json',
                success:function(res){
                    if(res.rc==0){
                        layer.msg('操作成功！', {icon: 1});
                        refreshTable("user");
                    }else{
                        layer.msg('操作失败！', {icon: 2});
                    }
                }
            });
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->

<!--CRUD简称增删改查操作，存在变化的地方有：列、查询条件、工具栏、操作栏-->
